package com.imufe.chemicalenterprisedangerwarning.security;

import com.imufe.chemicalenterprisedangerwarning.entity.po.UserPO;
import com.imufe.chemicalenterprisedangerwarning.mapper.UserMapper;
import com.imufe.chemicalenterprisedangerwarning.mapper.UserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

/**
 * @author BaiBan
 * @since 2022/10/20
 */

@Service
public class UserSecurityServiceImpl implements UserSecurityService {

    @Autowired
    UserMapper mapper;

    @Override
    public Long getUserId() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return Long.parseLong((String) authentication.getPrincipal());
    }

    @Override
    public UserPO getUser() {
        return mapper.selectById(getUserId());
    }
}